{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "#!/usr/bin/env python2.7\n",
    "# _*_ coding:utf-8 _*_\n",
    "\n",
    "#导入需要的python模块\n",
    "\n",
    "from multiprocessing import Process, Queue\n",
    "import os\n",
    "import cv2 as cv\n",
    "import numpy as np\n",
    "\n",
    "capture = cv.VideoCapture(0)                        # 创建一个VideoCapture对象\n",
    "while(True):\n",
    "    ret, frame = capture.read()                     # 一帧一帧读取视频\n",
    "    #gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)    # 对每一帧做处理,设置为灰度图\n",
    "    #cv.imshow('frame', gray)  # 显示结果\n",
    "    cv.imshow('frame', frame)  # 显示结果\n",
    "    if cv.waitKey(1) &0xFF == ord('q'):             # 按q停止\n",
    "        break\n",
    "\n",
    "capture.release()                                   # 释放cap,销毁窗口\n",
    "cv.destroyAllWindows()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "#!/usr/bin/env python2.7\n",
    "# _*_ coding:utf-8 _*_\n",
    "\n",
    "#导入需要的python模块\n",
    "\n",
    "from multiprocessing import Process, Queue\n",
    "import os\n",
    "import cv2 as cv\n",
    "import numpy as np\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        #定义本地显示、远程发送和本地存储的队列\n",
    "        disp_q = Queue()\n",
    "        remote_q = Queue()\n",
    "        store_q = Queue()\n",
    "        \n",
    "        #创建温度采集、本地显示温度、远程发送温度、本地温度存储进程\n",
    "        get_ds18b20_prog = Process(target=get_ds18b20, args=(\"温度采集进程\", disp_q, remote_q, store_q))\n",
    "        dig_disp_prog    = Process(target=digital_display, args=(\"本地温度显示进程\", disp_q))\n",
    "        send_remote_prog = Process(target=send_remote, args=(\"远程发送进程\", remote_q))\n",
    "        tmp_store_prog   = Process(target=tmp_store, args=(\"温度本地存储进程\", store_q))\n",
    "        \n",
    "        # 启动任务\n",
    "        get_ds18b20_prog.start()\n",
    "        dig_disp_prog.start()\n",
    "        send_remote_prog.start()\n",
    "        tmp_store_prog.start()\n",
    "\n",
    "        #等待启动的进程执行结束\n",
    "        get_ds18b20_prog.join()\n",
    "        dig_disp_prog.join()\n",
    "        send_remote_prog.join()\n",
    "        tmp_store_prog.join()\n",
    "\n",
    "    except KeyboardInterrupt:\n",
    "        print(\"任务被终止了\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
